Interface Switch

Currently, in RL, there exists a type switch statement (TYPE SWITCH or TYPE SWITCH STATIC):

TYPE SWITCH(value)
{
SomeClass: {;}
INT: {;}
BOOL: {;}
DEFAULT: {;}
}

But those type switches can only detect deriving types or the current static type of a value. However, in many instances, it is necessary to check whether a value statically implements one of multiple masks or dynamically implements one of multiple base classes. This is done with the interface switch statement (MASK SWITCH):

MASK SWITCH(value)
{
std::io::Streamable: value.stream(o);
std::CustomHashable: std::hash(value).stream(o);
DEFAULT: {;}
}

If a value is directly convertible to a certain mask or base class, the case is selected and all other cases are ignored. If there is no DEFAULT case, and the value cannot be converted into the mask, either the function becomes invalid, or an exception is thrown, depending on whether the condition could be decided at compile time. This is important when writing templated functions that should handle multiple classes of inputs:

[T:TYPE(Real || Natural)] sqrt(T x) T
{
    MASK SWITCH(x)
    {
    Real: {;} // Floating point implementation.
    Natural: {;} // Natural number implementation.
    // No DEFAULT: T must implement/derive from Real or Natural.
    }
}

Open problems: